package logic

import (
	"context"
	"doc-manage/model"

	"doc-manage/docrpc/docrpc"
	"doc-manage/docrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DocAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDocAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocAddLogic {
	return &DocAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DocAddLogic) DocAdd(in *docrpc.DocAddRequest) (*docrpc.DocAddResponse, error) {
	// todo: add your logic here and delete this line
	data := model.Doc{
		DocName:    in.DocName,
		Address:    in.Address,
		DocContent: in.DocContent,
	}

	if err := data.DocAdd(model.DB); err != nil {
		return nil, err
	}
	return &docrpc.DocAddResponse{
		DocId: int64(data.ID),
	}, nil
}
